package com.briup.run.web.listener;

import com.briup.run.bean.Memberinfo;
import com.briup.run.dao.MemberinfoMapper;
import com.briup.run.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.List;

/**
 * @Auther: liao
 * @Date: 2022/10/7-10-07-20:49
 * @Description：积分在前十的用户
 */
@WebListener
public class IndexListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        //得到上下文
        ServletContext servletContext = sce.getServletContext();
        SqlSession sqlSession = SqlSessionUtil.openSession();
        MemberinfoMapper memberinfoMapper = sqlSession.getMapper(MemberinfoMapper.class);
        List<Memberinfo> memberinfoList = memberinfoMapper.selectTen();
        //System.out.println(list);
        servletContext.setAttribute("memberinfoList",memberinfoList);

    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
